import 'package:flutter/material.dart';

import '../../commont/button.dart';
import '../../model/model.dart';
import '../../tool/assets.dart';

class ChSelect extends StatefulWidget {
  List<ChannelModel> ch_list;
  bool enable;
  void Function(ChannelModel) onClick;

  ChSelect(
      {super.key,
      required this.ch_list,
      required this.onClick,
      this.enable = true});

  @override
  State<ChSelect> createState() => _ChSelectState();
}

class _ChSelectState extends State<ChSelect> {
  @override
  Widget build(BuildContext context) {
    double screenWidth = MediaQuery.of(context).size.width;
    double w = (screenWidth - 5 * 7 - 20).toDouble() / 8.0;
    return SizedBox(
        height: w / 2 * GlobalConfig.scaleH,
        child: GridView.extent(
          maxCrossAxisExtent: w,
          mainAxisSpacing: 5,
          crossAxisSpacing: 5,
          childAspectRatio: 2 / GlobalConfig.scaleH,
          physics: const NeverScrollableScrollPhysics(),
          children: (widget.ch_list).map(($0) {
            bool enable = $0.enable && widget.enable;
            return kTextButton(
                name: $0.name,
                fontSize: 14,
                textColor: enable == false
                    ? Color_disEnable
                    : $0.select
                        ? Colors.white
                        : Colors.black,
                borderColor: enable == false
                    ? Color_disEnable
                    : $0.select
                        ? Color_theme
                        : Colors.black,
                groundColor: $0.select && enable ? Color_theme : Color_bg_view,
                enable: enable,
                onClick: (p0) {
                  setState(() {
                    $0.select = true;
                  });
                  widget.onClick($0);
                });
          }).toList(),
        ));
  }
}
